﻿using HighThroughput.Common;
using OSSUtility;
using Ozone.Device;
using Ozone.Help;
using Ozone.Models;
using Rubyer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Ozone.Views.Widget
{
    /// <summary>
    /// WindowSetParamDlg.xaml 的交互逻辑
    /// </summary>
    public partial class WindowSetParamDlg : Window
    {
        private string FDataID = "";
        private int nDevIndex = 0;
        static public bool ShowModal(string DataID,int DevIndex)
        {
            WindowSetParamDlg dlg = new WindowSetParamDlg(DataID,DevIndex);
            dlg.ShowDialog();
            return dlg.bIsOK;
        }

        public bool bIsOK = false;
        public WindowSetParamDlg(string DataID, int DevIndex)
        {
            FDataID = DataID;
            nDevIndex = DevIndex;

            InitializeComponent();
            txtTitle.Text = "参数设置";
            lblName.Content = DevConfigMain.Entity.getTitle(DataID)+":";
          
        }

        private bool IsCanSend()
        {
            if (FDataID == "PreheaterTemp1" || FDataID == "PreheaterTemp2")
            {
                if (!Tools.IsInRang(Utility.str2Double(txtVal.Text),
                                                        0,
                                                        800)
                                        )
                {
                    Message.Warning("预热器超出范围，范围" + 0
                                                    + "-"
                                                    + 800
                                                    + " ℃", 1000, true);
                    return false;
                }
            }


            return true;
        }

        private bool sendParam()
        {
          
            try
            {
                if (!IsCanSend())
                    return false;

                //发送参数

                bool bRet = false;

                //bRet = DeviceCenter.Entity.lstDevS10[nDevIndex].setParam(FDataID,
                //                    txtVal.Text);

                return bRet;
            }
            catch (Exception ex)
            {
               
             
                return false;
            }



        }

        private void btn_Click(object sender, RoutedEventArgs e)
        {
            if(!sendParam())
            {
                Message.Warning("执行失败", 1000, true);
                return ;

            }

            
            bIsOK = true;
            Close();
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            bIsOK = false;
            Close();
        }
    }
}
